-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lowering: Don't implicitly @nospecialize
macros
#57782
Conversation
dfdd613
to
75c3101
Compare
That was sort of the point though, since inference is supposed to reject these also anyways, so attempted specialization here is expected to be just wasted effort |
Why the invalidations in #57781 then? |
This PR doesn't seem to prevent any invalidation - the invalidations are exactly the same before and after applying this change on top of current |
Furthermore, I can confirm the invalidation of macro |
I'm not sure why the code is written this way (seems to be from c79e34c) but I don't think this is true? This code path does end up doing specialization. But then there is a check for functions starting with |
Oh we also insert |
Ah yep - Looks like that was auto-qualifying any |
75c3101
to
8d1ce02
Compare
There's not much purpose of this de-specialization, since macros are generally excluded from inference / compilation anyway (except for JuliaLang#57833 which was a bug) Since our AST is already relatively homogeneous, it's not clear that we gained much by this de-specialization when it was used. Arbitrarily de-specializing a function also often leads to bad (wide) edges in inference etc., causing frequent invalidations.
8d1ce02
to
9637b0e
Compare
@nospecialize
macros
I've updated this to implement the suggestion at #57833 (comment) We can land this PR, #57833, or both. |
Comparing the current master (3360a44) and the current state of this PR (9637b0e):
|
I am somewhat opposed to this PR, unless it can be shown conclusively that it does not harm existing code. Making it so it has to compile different copies of this function for different syntax forms is not generally a desirable feature for macros |
How would that be done? |
We could alternatively auto-insert a more precise type like But also since we're going to land #57833 I thought this only affects explicit |
I guess any potential problem with this would show up as precompile time? |
It'd show up as a failure to be able to generate a unspecialized precompile for macros and excess compilation (latency) when using macros (since we don't normally infer them, it would always be wasted time) |
Are you saying that the pre-compiled code would never be invoked for some reason? I'm still of the mindset that asking inference to infer poorly is worse (more edges, often more dynamic dispatch, etc.) than either asking it not to infer at all or to infer with normal quality |
That is possible. You'd need to generate pre-compiled for each possible combination of values that the user might splice into the macro expression, which generally just means precompile would refuse to generate anything
The normal behavior is to skip inference of these because of that. This PR makes the situation worse though, since now on top of refusing to infer them, you're also refusing to re-use existing code (because you're creating a situation where it is assumed to be inferred, which was previously not assumed). |
I don't really understand what this means - why does specialization affect whether we assume something is inferred, or whether we re-use code?
I understand this to mean we generally won't generate any code, so I don't understand what code we're refusing to re-use Anyway, what do you think of the P.S. I don't really feel strongly about this issue - just asking to develop my general understanding |
We cannot infer something for Any unless that is marked
In practice, that list is likely to be incomplete (at least Float32, UInt8/16/32/64/128, Int128, and BigInt are missing now) and could be also not stable since we could change JuliaSyntax to put more expressive nodes than simply Expr as a catch-all, or even because macros-writing-macros could put any sort of literal (such as a function object) there
|
Thanks for the explanations @vtjnash My vote is still that de-specialized inference here is not very useful (adds spurious invalidations and fails to pre-compile most of the code you were hoping to "re-use"), but I also agree that the union-split route is incompatible with direct I'm closing this for now in favor of the status quo - #57833 fixed the practical issues for now anyway |
Inspired by #57781 (kudos to @nsajko for another good find)
There's not much purpose of this de-specialization, since macros are generally excluded from inference / compilation anyway (except for #57833 which was a bug).
Since our AST is already relatively homogeneous, it's not clear that we gained much by this de-specialization when it was used. Arbitrarily de-specializing a function also often leads to bad (wide) edges in inference etc., causing frequent invalidations.